package com.zy.composeworld.ui.screens.image.image

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.imageResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import com.zy.composeworld.R


@OptIn(ExperimentalFoundationApi::class)
@Preview
@Composable
fun ImagePager001() {

    LazyColumn(
        modifier = Modifier
            .padding(16.dp)
            .background(color = Color.Gray),
        verticalArrangement = Arrangement.spacedBy(16.dp),
    ) {


        item {
            TextHead("从磁盘加载图片")

            Image(
                painter = painterResource(id = R.drawable.ic_like_normal),
                contentDescription = stringResource(id = R.string.dog_content_description)
            )

            Image(
                painter = painterResource(id = R.drawable.ic_like_selected),
                contentDescription = stringResource(id = R.string.dog_content_description)
            )
        }

        item {
            TextHead("从互联网加载图片")


            val url =
                "https://nimg.ws.126.net/?url=http%3A%2F%2Fdingyue.ws.126.net%2F2022%2F0415%2F686fb5a6j00raca2v002zc000hs00qnc.jpg&thumbnail=660x2147483647&quality=80&type=jpg"
            AsyncImage(
                model = url,
                modifier = Modifier.size(100.dp),
                contentDescription = "Translated description of what the image contains"
            )
        }


        item {
            TextHead("ImageBitmap")

            val imageBitmap = ImageBitmap.imageResource(R.drawable.ic_persion)
            Image(
                bitmap = imageBitmap,
                contentDescription = stringResource(id = R.string.dog_content_description)
            )
        }

        item {
            TextHead("ImageVector")
            val imageVector = ImageVector.vectorResource(id = R.drawable.ic_like_selected)
            Image(
                imageVector = imageVector,
                contentDescription = stringResource(id = R.string.dog_content_description)
            )
        }


    }

}


@Composable
private fun TextHead(text: String) {
    Text(text, fontWeight = FontWeight.Bold, color = Color.Red)
}